package com.dkd.manage.service.Impl;

import com.dkd.manage.mapper.SkuMapper;
import com.dkd.manage.pojo.dto.SkuQueryListDto;
import com.dkd.manage.pojo.entity.Sku;
import com.dkd.manage.result.PageResult;
import com.dkd.manage.service.SkuService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import io.swagger.models.auth.In;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
@Slf4j
public class SkuServiceImpl implements SkuService {


    @Autowired
    private SkuMapper skuMapper;

    /**
     * 分页查询商品列表
     * @param pageNum
     * @param pageSize
     * @param skuName
     * @return
     */
    @Override
    public PageResult<Sku> list(Integer pageNum, Integer pageSize, String skuName) {
        //开启分页
        PageHelper.startPage(pageNum, pageSize);
        //查询点位列表
        List<Sku> skuList =  skuMapper.list(skuName);
        //获取分页详情对象
        PageInfo<Sku> pageInfo = new PageInfo<>(skuList);
        //封装数据返回
        return new PageResult<>(pageInfo.getTotal(), pageInfo.getList());
    }


    /**
     * 新增商品
     * @param sku
     * @return
     */
    @Override
    public Integer add(Sku sku) {
        return skuMapper.add(sku);
    }

    /**
     * 根据id查询商品
     * @param id
     * @return
     */
    @Override
    public Sku getSkuById(Long id) {
        return skuMapper.getSkuById(id);
    }

    /**
     * 修改商品
     * @param sku
     * @return
     */
    @Override
    public Integer edit(Sku sku) {
        return skuMapper.edit(sku);
    }

    /**
     * 根据id删除商品
     * @param ids
     * @return
     */
    @Override
    public Integer deleteSkuById(Long[] ids) {

        return skuMapper.deleteSkuById(ids);
    }
}
